﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Reflection;
using BryhtCommon;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Imaging;

namespace MyRun.Controls
{
    public class ApproachHelper
    {
        public static bool JudgeFirstRun()
        {
            var versionFullName = Assembly.GetCallingAssembly().FullName;
            var isoVersionName = Isolated.Get("VersionFullName");

            if (isoVersionName == null || isoVersionName.ToString() != versionFullName)
            {
                Isolated.Set("VersionFullName", versionFullName);
                return true;
            }
            else
            {
                return false;
            }
        }

        public static void ShowApproach(Action complete)
        {
            int imageIndex = 1;
            Popup pop = new Popup();
            var backImage = new Image();
            backImage.Stretch = Stretch.None;
            backImage.VerticalAlignment = VerticalAlignment.Center;
            backImage.HorizontalAlignment = HorizontalAlignment.Center;
            backImage.Source = new BitmapImage(new Uri(string.Format("ApproachImages/{0}.png", imageIndex), UriKind.RelativeOrAbsolute));
            Border bob = new Border();
            bob.Background = new SolidColorBrush(Colors.Red);
            bob.Child = backImage;
            bob.Width = Application.Current.Host.Content.ActualWidth;
            bob.Height = Application.Current.Host.Content.ActualHeight;
            bob.Tap += (o, e) =>
            {
                imageIndex++;
                if (imageIndex == 8)
                {
                    pop.IsOpen = false;
                    complete();
                }
                backImage.Source = new BitmapImage(new Uri(string.Format("ApproachImages/{0}.png", imageIndex), UriKind.RelativeOrAbsolute));
            };
            pop.Child = bob;
            pop.IsOpen = true;
        }
    }
}
